﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Corina.Common
{
    public class DatetimeHelper
    {
        public static double GetDuration(DateTime dateStart, DateTime dateEnd)
        {
            TimeSpan tsStart = TimeSpan.FromTicks(dateStart.Ticks);
            TimeSpan tsEnd = TimeSpan.FromTicks(dateEnd.Ticks);

            TimeSpan ts = tsStart.Subtract(tsEnd).Duration();

            return ts.TotalSeconds;
        }

        public static int GetDurationDays(DateTime dateStart, DateTime dateEnd)
        {
            TimeSpan tsStart = TimeSpan.FromTicks(dateStart.Ticks);
            TimeSpan tsEnd = TimeSpan.FromTicks(dateEnd.Ticks);

            TimeSpan ts = tsStart - tsEnd; //tsStart.Subtract(tsEnd).Duration();

            return ts.Days;
        }

        public static void ConvertSeconds(double totalSeconds, out double days, out double hours, out double minutes, out double seconds)
        {
            double remine = 0;

            days = TimeSpan.FromSeconds(totalSeconds).TotalDays;

            days = Math.Floor(days);

            remine = totalSeconds - (days * 86400);

            hours = TimeSpan.FromSeconds(remine).TotalHours;

            hours = Math.Floor(hours);

            remine = remine - (hours * 3600);

            minutes = TimeSpan.FromSeconds(remine).TotalMinutes;

            minutes = Math.Floor(minutes);

            remine = remine - (minutes * 60);

            seconds = TimeSpan.FromSeconds(remine).TotalSeconds;

            seconds = Math.Floor(seconds);
        }
    }
}
